package org.jeecg.zhenxuan.Repository;

import org.jeecg.zhenxuan.Entity.UsersPoint;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public interface UserRepository extends JpaRepository<UsersPoint, Integer> {
    public UsersPoint getUserTestByOpenId(String openid);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(nativeQuery=true, value = "update userspoint set pointTotal =:pointTotal where openId =:openId")
    public  int updatePointTotal(@Param("pointTotal") Integer pointTotal, @Param("openId") String openId);


    /**
     * 根据openId和channel查询用户积分 单条记录
     * @param openId
     * @param channel
     * @return
     */
    public UsersPoint findUsersPointByOpenIdAndChannel(String openId, String channel);

    /**
     * add by 2020年1月1日 星期三
     * 将userspint表里的openid替换为小程序openid
     */

    @Modifying(clearAutomatically = true)
    @Query(nativeQuery = true , value = "update userspoint set openId = :tempId where openId = :openId")
    public int updateUsersPointOpenId(@Param("openId") String openId, @Param("tempId") String tempId);



}
